''微信公众号关注：VB小源码
''QQ群：344402874
''博客：https://www.cnblogs.com/vbee/
''个人微信：vbee_club

Imports System.Security.Cryptography
Imports System.Text

Public Class Form1
  Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    If My.Settings.reg = True Then
      Button1.Enabled = False
      Button2.Enabled = True
      Label4.Text = "已注册"
    Else
      Label4.Text = "未注册"
    End If

  End Sub

  Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    If TextBox1.Text = "" Then
      Button3_Click(sender, e)
    End If
    Try

      '私钥
      Dim s As String = "PFJTQUtleVZhbHVlPjxNb2R1bHVzPjdpSG91UlluMCtDc0NvaHhVamt3MmllVlRRek1TWjFNR2RqUlFvdVZwc2VQeWVnWVQvUHEyOWh2Nm9TNG5CVjRrcGsybG10dnJ4VlI2TUJ0NHhvM1BGTnR6d05JY1RtYmthNElHaUd2MjVCSDE3NHJITS92dDVZd1lrVTNIRjRBWmFiMzFFOTUzQWUzRUpESm1uYXo5UzRGNnF4NHE1bFE0SFAxbDY1SC9CVT08L01vZHVsdXM+PEV4cG9uZW50PkFRQUI8L0V4cG9uZW50PjxQPi82K0F3Y21HTlAyUk9SM21QWjJpaU9TdUt3Q2o3c2xNMFV6c1BQU2N4bEdZU01kelUxSVV4b3FzNmVYeDB6ZTNyeC9OSWVwQlpwYk5kZG1uSzVnM3h3PT08L1A+PFE+N216aFFXOTFFcWR6RHgyTE5qTStMRU96T0lWWGhFRTREWVBlVUJ4UjZvdlBEeDQ3bXpMclVyeHlRdzFmdFJIZkoweHdPajg0bHk5YzdWbHRJZEdGUXc9PTwvUT48RFA+blRQa3NFRWRXTnRHUEozYmY2cTUwZnozOE15Vi9peWFKRjF0S2hVamh2T0g4OGRkYXE4ZXd1dGtZUExWK2cxWnpEeDdQUXp3WlFqM0RpeGlFZldtNVE9PTwvRFA+PERRPmVvd0NGNVVITXFoWXJsczhFNGF4SFNWSzkvRXBjM1BtTUtRbjN6cy9LM1BpNEYxa3U3ZW5WcVkvZ0pGZU1QNVhtYVpqUkx6OEJGRTJ6VlFha0xoVmF3PT08L0RRPjxJbnZlcnNlUT5pbysydmd1ekM3Y3U3VmV3bkt1TGdGM2JwajlRL3VHZG80K0dnc0xTVThGTllQL1QweTR4S0plZnArQlJ2dWVwL05icWlGc3hHcmJxWFB6OWJvbHZVQT09PC9JbnZlcnNlUT48RD5lV3d1NTFsbHU0Sy9GcXZWNUpBbTJjWC9PZ2VCanpPMm55TlFLSGRXT25GZFh4MktjQkkydWh6VmpDWmFuN1BQQkNrOWpWdUEyaXlyMUZ0eWJLOXNZOGxQeUoyVVJKYTVHZ1pEWWVzdVhJa290TWVwbGFaeGMvZk90V1QvaXFEU3pBdHpmRDNBL1BmS2VySm1qRStOUzBldG81TGtucTNwLzhYeCtOMkcxVzA9PC9EPjwvUlNBS2V5VmFsdWU+"
      Dim de_cont As String = String.Empty
      Using rsa As New RSACryptoServiceProvider()
        rsa.FromXmlString(Encoding.Default.GetString(Convert.FromBase64String(s)))
        Dim de_data As Byte() = rsa.Decrypt(Convert.FromBase64String(RichTextBox1.Text), False)
        de_cont = Encoding.GetEncoding("GB2312").GetString(de_data)
      End Using

      Dim fg As Boolean = de_cont = TextBox1.Text
      If fg Then
        My.Settings.reg = True
        My.Settings.Save()
        Button1.Enabled = False
        Button2.Enabled = True
        Label4.Text = "已注册"
        MessageBox.Show("注册验证成功")
      Else
        My.Settings.reg = False
        My.Settings.Save()
        Button1.Enabled = True
        Button2.Enabled = False
        MessageBox.Show("注册验证失败")
      End If
    Catch ex As Exception
      My.Settings.reg = False
      My.Settings.Save()
      Button1.Enabled = True
      Button2.Enabled = False
      MessageBox.Show("注册验证失败")
    End Try
  End Sub

  Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged

  End Sub

  Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    My.Settings.reg = False
    My.Settings.Save()
    Label4.Text = "未注册"
    Button1.Enabled = True
    Button2.Enabled = False
  End Sub

  Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
    Dim mc As New Cls_MachineCode
    TextBox1.Text = mc.GenerateMachineCode()
  End Sub

  Private Sub Label4_Click(sender As Object, e As EventArgs) Handles Label4.Click

  End Sub
End Class
